﻿var isClient = true;
var message = '';
function getText() {
    var html = '';
    message = $('#textInput').val();
    if (isClient == true && message != '') {
        html = '<div class="box-chat-main-content">';
        html += '<div class="side-name">Bạn</div>';
        html += '<div class="content">';
        html += message;
        html += '</div>';
        $('#mainChat').append(html);
        resetTextInput();
    }
}
function reply(msg) {
    var html = '';
    html = '<div class="box-chat-main-content">';
    html += '<div class="side-name">Bác sỹ</div>';
    html += '<div class="content">';
    html += msg;
    html += '</div></div>';
    $('#mainChat').append(html);
}
function sendMessage() {
    $('#smSymptom').bind('click', function () {
        if (isClient == true) {
            getText();
            if (message != '') {
                processMessage();
                showMask();
            } else alert("Please enter something!");
            isClient = false;
        }
    });
}
function showMask() {
    $("#textMask").css('display', 'block');
}
function hideMask() {
    $("#textMask").css('display', 'none');
}
function resetTextInput() {
    $('#textInput').val('');
}
function processMessage() {
    var value = {
        msg: message
    }
    $.ajax({
        data: value,
        url: './clientMessage/ngramAlgorithms',
        success: function (data) {
            isClient = true;
            hideMask();
            reply(data);
            message = '';
        }
    });
}